<?php
/*
 * @Author: your name
 * @Date: 2020-12-23 12:01:16
 * @LastEditTime: 2020-12-28 10:14:08
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /special/application/adminapiv3/service/module_manage/hgshield/IpsOriginalRule.php
 */

namespace app\adminapiv3\service;


class IpsOriginalRule extends BaseService
{
    public function list($hostId, $params)
    {
        //1.检查系统
        $hostServer = new \app\common\service\Host();
        $hostInfo = $hostServer->info($hostId);
        if ($hostInfo['os'] == 1) {
            $this->setError($this->CODE_FAIL, 'windows无规则');
            return false;
        }

        //2. 检查是否开启IPS模式
        $ipsConfigServer = new \app\common\service\IpsConfig();
        $info = $ipsConfigServer->findData(['host_id' => $hostId]);

        if(empty($info) || ($info['type'] != 1 && $info['status'] == 1)){
            $this->setError($this->CODE_FAIL,'未开启IPS设置');
            return false;
        }

        $server = new \app\common\service\IpsOriginalRule();
        $list = $server->list($hostId, $params);

        return $list;
    }

    /**
     * @name 修改
     * @param $id
     * @param $update
     * @author wx
     * @date 2019/11/21 10:51
     */
    public function modify($id, $update)
    {
        $IpsOriginalRule = new \app\common\service\IpsOriginalRule();
        $return = $IpsOriginalRule->checkRequestData($update['host_id'], $id);
        $IpsOriginalRule->modify(['id' => $id], $update);

        return $return;
    }

    /**
     * @name 删除
     * @param $id
     * @author wx
     * @date 2019/11/21 10:56
     */
    public function del($id, $hostId)
    {
        $IpsOriginalRule = new \app\common\service\IpsOriginalRule();
        $return = $IpsOriginalRule->checkRequestData($hostId, $id);
        $IpsOriginalRule->del(['id' => $id, 'host_id' => $hostId]);

        return $return;
    }

    public function importRule($hostId)
    {
        //1.检查系统
        $hostServer = new \app\common\service\Host();
        $hostInfo = $hostServer->info($hostId);
        if ($hostInfo['os'] == 1) {
            $this->setError($this->CODE_FAIL, 'windows无规则');
            return false;
        }

        //2. 检查是否开启IPS模式
        $ipsConfigServer = new \app\common\service\IpsConfig();
        $info = $ipsConfigServer->findData(['host_id' => $hostId]);

        if(empty($info) || ($info['firewall'] == 1)){
            $this->setError($this->CODE_FAIL,'已锁定防火墙，此操作无效!');
            return false;
        }

        return true;
    }
}